package io.adrainty.bolee.insurance.web;

import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.insurance.models.aggregate.EarningResultDTO;
import io.adrainty.bolee.insurance.models.entity.WarrantyEntity;
import io.adrainty.bolee.insurance.models.request.DoInsuranceDTO;
import io.adrainty.bolee.insurance.service.IInsuranceService;
import io.adrainty.bolee.insurance.service.IWarrantyService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author AdRainty
 * @version V1.0.0
 * @since 2025/8/24 下午9:13
 */

@RestController
@RequestMapping("/insure")
public class InsuranceController {

    @Resource
    private IInsuranceService insuranceService;

    @Resource
    private IWarrantyService warrantyService;

    @PostMapping("/do-premium")
    @Operation(summary = "保险试算")
    public ResultDTO<String> calculatePremium(@RequestBody DoInsuranceDTO doInsuranceDTO) {
        String priceResult = insuranceService.calculatePremium(doInsuranceDTO);
        return ResultDTOUtil.success(priceResult);
    }

    @PostMapping("do-earnings")
    @Operation(summary = "收益试算")
    public ResultDTO<EarningResultDTO> calculateEarnings(@RequestBody DoInsuranceDTO doInsuranceDTO) {
        EarningResultDTO priceResult = insuranceService.calculateEarnings(doInsuranceDTO);
        return ResultDTOUtil.success(priceResult);
    }

    @PostMapping("do-insure")
    @Operation(summary = "保险购买")
    public ResultDTO<WarrantyEntity> doInsure(@RequestBody DoInsuranceDTO doInsuranceDTO) {
        WarrantyEntity result = warrantyService.doInsure(doInsuranceDTO);
        result.desensitize();
        return ResultDTOUtil.success(result);
    }

    @PostMapping("sign-contract/{warrantyOrderId}/{tradingChannel}")
    @Operation(summary = "签约")
    public ResultDTO<String> signContract(@PathVariable("warrantyOrderId") Long warrantyOrderId,
                                           @PathVariable("tradingChannel") String tradingChannel) {
        String signResult = warrantyService.signContract(warrantyOrderId, tradingChannel);
        return ResultDTOUtil.success(signResult);
    }

}
